Skip to content

LLDP: add IEEE 802.1Q and 802.1AX org-specific TLVs - #4970

Open
ali-keys wants to merge 2 commits into
secdev:masterfrom
ali-keys:lldp-ieee8021-tlvs
Open

LLDP: add IEEE 802.1Q and 802.1AX org-specific TLVs#4970
ali-keys wants to merge 2 commits into
secdev:masterfrom
ali-keys:lldp-ieee8021-tlvs

Conversation

@ali-keys

Copy link
Copy Markdown
Contributor

Hi everyone,

This PR adds 15 new org-specific TLVs for IEEE 802.1Q:

  • Port VLAN ID (PVID)
  • Port and Protocol VLAN ID (PPVID)
  • VLAN Name
  • Protocol Identity
  • VID Usage Digest
  • Management VID
  • Link Aggregation (this TLV is from 802.1AX)
  • Congestion Notification
  • ETS Configuration
  • ETS Recommendation
  • PFC Configuration
  • Application Priority
  • EVB
  • CDCP
  • Application VLAN

First, I wanted to implement only the ones that I needed (VLAN stuff), but then decided to implement all of them.
The code has been written mostly by AI. I've reviewed and corrected every line of it.

@polydroi

Copy link
Copy Markdown

Thanks for the PR.

Could you please check if it is possible to add interoperability tests with existing tools or libraries, such as lldpd, to the unit tests.

@ali-keys

ali-keys commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the PR.

Could you please check if it is possible to add interoperability tests with existing tools or libraries, such as lldpd, to the unit tests.

Hi Nils,

by interoperability tests you mean: Making a real environment -> capturing everything -> writing tests based on the pcaps to make sure it gets parsed correctly? Like the last test (Wireshark sample: Summit300-48*)?

* https://github.com/secdev/scapy/pull/4970/changes#diff-cd75a14a55c0b70a338abe750de68641d9a5c2c43acee32f99291161bb66100eR1689-R1742

@polydroi

Copy link
Copy Markdown

No, those tests are also important, but if possible I have something like this in mind.

Start lldpd with a certain configuration in a subprocess,
Start your test code that interacts with lldpd. Evaluate the test.
Stop the subprocess.

In this way we can automatically verify the interaction with a real world application/libray.

@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.97175% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.52%. Comparing base (5fb7637) to head (5e824af).

Files with missing lines Patch % Lines
scapy/contrib/lldp.py 68.75% 50 Missing ⚠️
scapy/autorun.py 31.25% 11 Missing ⚠️
scapy/main.py 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (5fb7637) and HEAD (5e824af). Click for more details.

HEAD has 10 uploads less than BASE
Flag BASE (5fb7637) HEAD (5e824af)
12 2
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #4970       +/-   ##
===========================================
- Coverage   80.49%   47.52%   -32.97%     
===========================================
  Files         390      372       -18     
  Lines       96770    96558      -212     
===========================================
- Hits        77891    45894    -31997     
- Misses      18879    50664    +31785     
Files with missing lines Coverage Δ
scapy/main.py 21.64% <0.00%> (-46.83%) ⬇️
scapy/autorun.py 61.41% <31.25%> (-22.41%) ⬇️
scapy/contrib/lldp.py 61.81% <68.75%> (-32.82%) ⬇️

... and 337 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gpotter2

gpotter2 commented May 9, 2026

Copy link
Copy Markdown
Member

LGTM, but the doc tests fail with

/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_AppPriority_Entry:9: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_AppVLANEntry:9: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_Priority:14: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_Priority:17: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_VLAN:12: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_VLAN:15: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:12: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:15: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:17: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:18: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_ETS_Configuration:13: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_ETS_Configuration:14: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_EVB:11: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_EVB:15: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_PFC_Configuration:13: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_PFC_Configuration:14: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Port_And_Protocol_VLAN_ID:13: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Port_And_Protocol_VLAN_ID:14: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]

@ali-keys

Copy link
Copy Markdown
Contributor Author

@gpotter2 I fixed the docstrings.

@polydroi I have had some progress with interoperability tests (not pushed), but not all of the TLVs are implemented in lldpd/lldpad.

@polybassa

Copy link
Copy Markdown
Contributor

Regarding the interoperability tests, it doesn't matter if not all IDs are supported. At least we get an overall good coverage on AI generated code.

…rg-specific dispatch

AI-Assisted: yes (Claude Sonnet 4.6)
@ali-keys
ali-keys force-pushed the lldp-ieee8021-tlvs branch from 8e2d6e7 to bc7e272 Compare July 31, 2026 09:50
@ali-keys

Copy link
Copy Markdown
Contributor Author

@polybassa I added interoperability tests for LLDP (via lldp and lldpad).

While writing the tests I also found a bug in autorun.py that makes tests hang forever.
The bug has two parts:

  • CPython gh-130250 (affected versions: 3.12.0-3.12.9 and 3.13.0-3.13.2)
  • q.put() having no exception handling

I also made the regression tests to not fail when IPython is missing. (the change in main.py)

PoC for the hang - tested with Python 3.12.3 (affected) and 3.14.6 (not affected):

"""
POC: UTScapy (scapy.autorun) hangs forever when a test raises, on affected
"""

import sys


def check_python():
    v = sys.version_info
    affected = (v[:2] == (3, 12) and v[2] < 10) or (v[:2] == (3, 13) and v[2] < 3)
    print(f"Python {sys.version.split()[0]} -- affected by gh-130250: {affected}")
    return affected


def demo_cpython_bug():
    """Reproduce CPython gh-130250 standalone (no scapy)."""
    import io
    import traceback

    try:
        raise RuntimeError("boom")
    except RuntimeError:
        sys.last_exc = sys.exc_info()[1]
        sys.last_type = type(sys.last_exc)
        sys.last_value = sys.last_exc
        sys.last_traceback = sys.last_exc.__traceback__
        buf = io.StringIO()
        try:
            traceback.print_last(file=buf)
            print("no error -- Python is fixed")
        except AttributeError as e:
            print(f"reproduced gh-130250: {e!r}")


def demo_scapy_hang():
    """Trigger the full UTScapy hang path."""
    from scapy.autorun import autorun_get_interactive_session
    cmds = "assert False, 'boom'\n"
    print("calling autorun_get_interactive_session -- hangs on affected Python")
    out, res = autorun_get_interactive_session(cmds, timeout=5)
    print("returned:", repr(res))


if __name__ == "__main__":
    check_python()
    demo_cpython_bug()
    demo_scapy_hang()

+ Emulate interact test to work without IPython installed

AI-Assisted: yes (Claude Opus 4.7)
@ali-keys
ali-keys force-pushed the lldp-ieee8021-tlvs branch from bc7e272 to 5e824af Compare July 31, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants